package com.green.common;

import java.util.HashMap;
import java.util.Map;

/**
 * 上下文变量
 * 
 * @author Hou Peiqin
 * 
 */
public class ContextHolder {
	private static final ThreadLocal<Map<String, Object>> contextHolder = new ThreadLocal<Map<String, Object>>();
	private static final String DATA_SOURCE = "DATA_SOURCE";
	public static void setDataSource(String dataSource) {
		Map<String, Object> holder = contextHolder.get();
		if(holder == null) {
			holder = new HashMap<String, Object>();
			contextHolder.set(holder);
		}
		holder.put(DATA_SOURCE, dataSource);
	}

	public static String getDataSource() {
		Map<String, Object> holder = contextHolder.get();
		if(holder == null) return null;
		return (String) holder.get(DATA_SOURCE);
	}

	public static void clear() {
		contextHolder.remove();
	}
}
